home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap05 / ExampleClient.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-06  |  2.7 KB  |  76 lines

  1. import java.io.DataInputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.IOException;
  4. import java.net.Socket;
  5. import java.net.UnknownHostException;
  6. import vrml.BaseNode;
  7. import vrml.Browser;
  8. import vrml.Event;
  9. import vrml.field.ConstSFRotation;
  10. import vrml.field.SFNode;
  11. import vrml.field.SFVec3f;
  12. import vrml.node.Node;
  13. import vrml.node.Script;
  14.  
  15. public class ExampleClient extends Script {
  16.    public static final int PORT = 4130;
  17.    public static final String HOST = "localhost";
  18.    Socket socket;
  19.    // $FF: renamed from: in java.io.DataInputStream
  20.    DataInputStream field_0;
  21.    DataOutputStream out;
  22.    // $FF: renamed from: b vrml.Browser
  23.    Browser field_1;
  24.    Node target;
  25.    SFVec3f trans;
  26.    float[] coord;
  27.    float[] rotation;
  28.  
  29.    public void initialize() {
  30.       this.field_1 = ((BaseNode)this).getBrowser();
  31.       this.target = (Node)((SFNode)((Script)this).getField("target")).getValue();
  32.       this.trans = (SFVec3f)this.target.getExposedField("translation");
  33.       this.coord = new float[3];
  34.       this.rotation = new float[4];
  35.  
  36.       try {
  37.          this.socket = new Socket("localhost", 4130);
  38.          this.field_0 = new DataInputStream(this.socket.getInputStream());
  39.          this.out = new DataOutputStream(this.socket.getOutputStream());
  40.       } catch (UnknownHostException var1) {
  41.          this.field_1.setDescription("Unknown host: localhost");
  42.       } catch (Exception var2) {
  43.          this.field_1.setDescription("Connection error");
  44.       }
  45.    }
  46.  
  47.    public void processEvent(Event var1) {
  48.       ((ConstSFRotation)var1.getValue()).getValue(this.rotation);
  49.  
  50.       try {
  51.          this.trans.getValue(this.coord);
  52.          this.out.writeFloat(this.rotation[3]);
  53.          this.out.writeFloat(this.coord[0]);
  54.          this.out.writeFloat(this.coord[1]);
  55.          this.out.writeFloat(this.coord[2]);
  56.          this.coord[0] = this.field_0.readFloat();
  57.          this.coord[1] = this.field_0.readFloat();
  58.          this.coord[2] = this.field_0.readFloat();
  59.          this.field_1.setDescription("position: " + this.coord[0] + "," + this.coord[1] + "," + this.coord[2]);
  60.          this.trans.setValue(this.coord);
  61.       } catch (IOException var3) {
  62.          this.field_1.setDescription("IOException:  " + var3);
  63.       }
  64.    }
  65.  
  66.    public void shutdown() {
  67.       try {
  68.          this.out.close();
  69.          this.field_0.close();
  70.          this.socket.close();
  71.       } catch (Exception var1) {
  72.          this.field_1.setDescription("Connection close error");
  73.       }
  74.    }
  75. }
  76.